import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        UnionSet u = new UnionSet(n+1);
        for(int i = 0;i<n;i++) {
          int a = scan.nextInt();
          int b = scan.nextInt();
          if(!u.union(a,b)) {
              u.print(a,b);
          }

        }
        LinkedList<Integer>  ret = new LinkedList<>();

        scan.close();
    }
}

class UnionSet {
  public int[] elem;
  public UnionSet(int n) {
    this.elem = new int[n];
      Arrays.fill(elem,-1);
  }


  public int findRoot(int x) {
    if(x < 0) {
      return -1;
    }
    while(elem[x] >= 0) {
      x = elem[x];
    }
    return x;
  }

  public boolean union(int x,int y) {
    int x1 = findRoot(x);
    int x2 = findRoot(y);
    if(x1 == x2) {
       return false;
    } else {
        if(x < y) {
            if(elem[y] == -1) {
                elem[y] = x;
            } else {
                elem[x] = y;
            }
        } else {
            if(elem[x] == -1) {
                elem[x] = y;
            } else {
                elem[y] = x;
            }
        }
    }
    return true;
  }

  public void print(int x,int y) {
      Set<Integer> set = new TreeSet<>();
      while(elem[x] >=0) {
          set.add(x);
          x = elem[x];
      }
      set.add(x);
      while(elem[y] >= 0) {
          if(set.contains(y)) {
              while(elem[y] >=0) {
                  set.remove(y);
                  y = elem[y];
              }
              break;
          }
          set.add(y);
          y = elem[y];
      }
      int size = set.size();
      int i = 0;
      for(Integer a : set) {
          if(i == set.size()-1) {
              System.out.print(a);
          } else {
              System.out.print(a + " ");
          }
          i++;

      }
  }
}